// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2020, Konrad Dybcio
 */

/dts-v1/;

#include "msm8992.dtsi"
#include "pm8994.dtsi"
#include "pmi8994.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/gpio-keys.h>

/ {
	model = "Xiaomi Mi 4C";
	compatible = "xiaomi,libra", "qcom,msm8992";
	/* required for bootloader to select correct board */
	qcom,msm-id = <251 0 252 0>;
	qcom,pmic-id = <65545 65546 0 0>;
	qcom,board-id = <12 0>;

	/* This enables graphical output via bootloader-enabled display */
	chosen {
		bootargs = "earlycon=tty0 console=tty0";

		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		framebuffer0: framebuffer@3404000 {
			status= "okay";
			compatible = "simple-framebuffer";
			reg = <0 0x3404000 0 (1080 * 1920 * 3)>;
			width = <1080>;
			height = <1920>;
			stride = <(1080 * 3)>;
			format = "r8g8b8";
		};
	};

	gpio_keys {
		compatible = "gpio-keys";
		input-name = "gpio-keys";
		#address-cells = <1>;
		#size-cells = <0>;
		autorepeat;

		button@0 {
			label = "Volume Up";
			gpios = <&pm8994_gpios 3 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_VOLUMEUP>;
			wakeup-source;
			debounce-interval = <15>;
		};
	};

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		/* This is for getting crash logs using Android downstream kernels */
		ramoops@dfc00000 {
			compatible = "ramoops";
			reg = <0x0 0xdfc00000 0x0 0x40000>;
			console-size = <0x10000>;
			record-size = <0x10000>;
			ftrace-size = <0x10000>;
			pmsg-size = <0x20000>;
		};

		continuous_splash: framebuffer@3401000{
			reg = <0x0 0x3401000 0x0 0x2200000>;
			no-map;
		};

		dfps_data_mem: dfps_data_mem@3400000 {
			reg = <0x0 0x3400000 0x0 0x1000>;
			no-map;
		};

		peripheral_region: peripheral_region@7400000 {
			reg = <0x0 0x7400000 0x0 0x1c00000>;
			no-map;
		};

		modem_region: modem_region@9000000 {
			reg = <0x0 0x9000000 0x0 0x5a00000>;
			no-map;
		};

		tzapp: modem_region@ea00000 {
			reg = <0x0 0xea00000 0x0 0x1900000>;
			no-map;
		};
	};
};

&blsp_i2c2 {
	status = "okay";

	/* Atmel or Synaptics touchscreen */
};

&blsp_i2c5 {
	status = "okay";

	/* Silabs si4705 FM transmitter */
};

&blsp_i2c6 {
	status = "okay";

	/* NCI NFC,
	 * TI USB320 Type-C controller,
	 * Pericom 30216a USB (de)mux switch
	 */
};

&blsp_i2c7 {
	status = "okay";

	/* cm36686 proximity and ambient light sensor */
};

&blsp_i2c13 {
	status = "okay";

	/* ST lsm6db0 gyro/accelerometer */
};

&blsp2_uart2 {
	status = "okay";
};

&rpm_requests {
	pm8994-regulators {
		compatible = "qcom,rpm-pm8994-regulators";

		vdd_l1-supply = <&pm8994_s7>;
		vdd_l2_26_28-supply = <&pm8994_s3>;
		vdd_l3_11-supply = <&pm8994_s3>;
		vdd_l4_27_31-supply = <&pm8994_s3>;
		vdd_l5_7-supply = <&pm8994_s3>;
		vdd_l6_12_32-supply = <&pm8994_s5>;
		vdd_l8_16_30-supply = <&vreg_vph_pwr>;
		vdd_l9_10_18_22-supply = <&vreg_vph_pwr>;
		vdd_l13_19_23_24-supply = <&vreg_vph_pwr>;
		vdd_l14_15-supply = <&pm8994_s5>;
		vdd_l17_29-supply = <&vreg_vph_pwr>;
		vdd_l20_21-supply = <&vreg_vph_pwr>;
		vdd_l25-supply = <&pm8994_s5>;
		vdd_lvs1_2 = <&pm8994_s4>;

		pm8994_s1: s1 {
			/* unused */
			status = "disabled";
		};

		pm8994_s2: s2 {
			/* unused */
			status = "disabled";
		};

		pm8994_s3: s3 {
			regulator-min-microvolt = <1300000>;
			regulator-max-microvolt = <1300000>;
		};

		pm8994_s4: s4 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
			regulator-always-on;
			regulator-system-load = <325000>;
		};

		pm8994_s5: s5 {
			regulator-min-microvolt = <2150000>;
			regulator-max-microvolt = <2150000>;
		};

		pm8994_s7: s7 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l1: l1 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l2: l2 {
			regulator-min-microvolt = <1250000>;
			regulator-max-microvolt = <1250000>;
		};

		pm8994_l3: l3 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8994_l4: l4 {
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
		};

		pm8994_l5: l5 {
			/* unused */
			status = "disabled";
		};

		pm8994_l6: l6 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l7: l7 {
			/* unused */
			status = "disabled";
		};

		pm8994_l8: l8 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l9: l9 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l10: l10 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l11: l11 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8994_l12: l12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l13: l13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
		};

		pm8994_l14: l14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l15: l15 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l16: l16 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <2700000>;
		};

		pm8994_l17: l17 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <2700000>;
		};

		pm8994_l18: l18 {
			regulator-min-microvolt = <2850000>;
			regulator-max-microvolt = <2850000>;
			regulator-always-on;
		};

		pm8994_l19: l19 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8994_l20: l20 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-always-on;
			regulator-boot-on;
			regulator-allow-set-load;
			regulator-system-load = <570000>;
		};

		pm8994_l21: l21 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-always-on;
		};

		pm8994_l22: l22 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3000000>;
		};

		pm8994_l23: l23 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8994_l24: l24 {
			regulator-min-microvolt = <3075000>;
			regulator-max-microvolt = <3150000>;
		};

		pm8994_l25: l25 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l26: l26 {
			regulator-min-microvolt = <987500>;
			regulator-max-microvolt = <987500>;

		};

		pm8994_l27: l27 {
			regulator-min-microvolt = <1050000>;
			regulator-max-microvolt = <1050000>;
		};

		pm8994_l28: l28 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l29: l29 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8994_l30: l30 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l31: l31 {
			regulator-min-microvolt = <1262500>;
			regulator-max-microvolt = <1262500>;
		};

		pm8994_l32: l32 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
	};
};

&sdhc_1 {
	status = "okay";

	mmc-hs400-1_8v;
	vmmc-supply = <&pm8994_l20>;
	vqmmc-supply = <&pm8994_s4>;
};
